import Taro from '@tarojs/taro'
import app from '../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            cityRang: [[], []],
            case_detail: {
                id:'',
                patient_name: '',
                gender: '',
                birthday: '',
                phone: '',
                province: '',
                city: '',
                occupation: '',
            },
            pdata: {},
            cities: []
        };
        return this.state;
    },

    updateCase_detail() {
        var me = this;
        if(!this.state.case_detail.patient_name) {
            this.showToast('请填写姓名');
            return;
        }

        // if(!this.state.case_detail.gender) {
        //     this.showToast('请选择性别');
        //     return;
        // }

        // if(!this.state.case_detail.birthday) {
        //     this.showToast('请选择出生日期');
        //     return;
        // }
        app.post("api/case_details/update", me.state.case_detail, function(res) {
            me.redirectTo('../editCase/editCase?id=' + me.state.case_detail.id);
        });
    },

    componentWillMount () {
        this.init();
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleDetailChange(name, event) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }

        if(names.length > 1) {
            temp[names[i]] = event.detail.value;
            this.setState({n: temp});
        } else {
            this.setState({n: event.detail.value});
        }
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        
        if(names.length > 1) {
            temp[names[i]] = v;
            this.setState({n: temp});
        } else {
            this.setState({n: v});case_detail
        }
    },
    redirectTo(url) {
        app.redirectTo(url);
    },

    getData2(){
        let me = this
        let data = {id:this.$router.params.id}
        app.get('web/case/get',data,(res)=>{
            me.setState({
                case_detail: res.data.result
            })
        })
    },
    componentDidMount () {      
        this.getData2();
    },
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
